{include file="public/admin_head.html"}

<body>

<form class="form-horizontal" method ="post" action ="../index.php?act=admin&st=modifypassword" onsubmit="return valiadate(this)">
      <fieldset>
	<legend><B>修改用户密码<B></legend>
	<input type="hidden" value="{$session.token}" name="token">
	<input type="hidden"  value="{$id}" name="id">
	<div class="control-group">
	  <label for="input01" class="control-label">用户名称：<font color="#FF0000">*</font></label>
	  <div class="controls">
	    <input type="text" id="input01" class="input-xlarge" value="{$rs.username}" name="username" readonly="readonly">
	  </div>
	</div>

	<div class="control-group">
	  <label for="input01" class="control-label">原始密码：<font color="#FF0000">*</font></label>
	  <div class="controls">
	    <input type="password" id="input01" class="input-xlarge" value="" name="oldpassword">
	  </div>
	</div>
	
	<div class="control-group">
	  <label for="input01" class="control-label">新密码：<font color="#FF0000">*</font></label>
	  <div class="controls">
	    <input type="password" id="input01" class="input-xlarge" value="" name="newpassword">
	  </div>
	</div>

      </fieldset>
	<div class="form-actions">
		<button class="btn btn-primary" type="submit">保存更改</button>
		<a href="./index.php?act=admin&st=main" class="btn">返回</a>
	</div>
    </form>
<script>
function CountChar(str, n, m){
    var len = str.length;
    for (var i=0; i < len-n; i++){
       var tmp = str.substring(i, i+n);
       var num = checkCount(str, tmp);
       if (num >= m){
           var regex = '^[\\w]*('+tmp+'){'+m+'}[\\w]*$';
           if ((new RegExp(regex)).test(str)){
              return false;
             break;
           }else{
              continue;
           }
       }
    }
    return true;
}

function checkCount(str, tmp){
    return str.split(tmp).length-1;
}

function valiadate(obj){
		var newpassword = $("input[name=newpassword]").val();
		var oldpassword = $("input[name=oldpassword]").val();
		var id = $("input[name=id]").val();
		var regex1 = /^[a-zA-Z0-9_!@#$%^&*_+]{8,16}$/;
        var regex2 = /^[a-zA-Z]{8,16}$/;
        var regex6 = /^[0-9]{6,16}$/;
        var regex3 = /([a-zA-Z0-9])\1{2}/;
        var regex5 = /^[a-zA-Z0-9]{8,16}$/;
        var regex7 = /^[a-zA-Z_!@#$%^&*+]{8,16}$/;
        var regex4 = /[\w]*(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){3}|(?:A(?=B)|B(?=C)|C(?=D)|D(?=E)|E(?=F)|F(?=G)|G(?=H)|H(?=I)|I(?=J)|J(?=K)|K(?=L)|L(?=M)|M(?=N)|N(?=O)|O(?=P)|P(?=Q)|Q(?=R)|R(?=S)|S(?=T)|T(?=U)|U(?=V)|V(?=W)|W(?=X)|X(?=Y)|Y(?=Z)){3}|(?:a(?=b)|b(?=c)|c(?=d)|d(?=e)|e(?=f)|f(?=g)|g(?=h)|h(?=i)|i(?=j)|j(?=k)|k(?=l)|l(?=m)|m(?=n)|n(?=o)|o(?=p)|p(?=q)|q(?=r)|r(?=s)|s(?=t)|t(?=u)|u(?=v)|v(?=w)|w(?=x)|x(?=y)|y(?=z)){3}|(?:z(?=y)|y(?=x)|x(?=w)|w(?=v)|v(?=u)|u(?=t)|t(?=s)|s(?=r)|r(?=q)|q(?=p)|p(?=o)|o(?=n)|n(?=m)|m(?=l)|l(?=k)|k(?=j)|j(?=i)|i(?=h)|h(?=g)|g(?=f)|f(?=e)|e(?=d)|d(?=c)|c(?=b)|b(?=a)){3}|(?:Z(?=Y)|Y(?=X)|X(?=W)|W(?=V)|V(?=U)|U(?=T)|T(?=S)|S(?=R)|R(?=Q)|Q(?=P)|P(?=O)|O(?=N)|N(?=M)|M(?=L)|L(?=K)|K(?=J)|J(?=I)|I(?=H)|H(?=G)|G(?=F)|F(?=E)|E(?=D)|D(?=C)|C(?=B)|B(?=A)){3})\w/;
        if(!regex1.test(newpassword)){
			alert("密码必须数字+字母+字符组成长度8-16位");
			return false;
		}else if(regex2.test(newpassword)){
			alert("密码必须数字+字母+字符组成");
			return false;
		}else if(regex6.test(newpassword)){
			alert("密码必须至少包含一个字母");
			return false;
		}else if(regex5.test(newpassword)){
			alert("密码必须至少包含一个字符");
			return false;
		}else if(regex7.test(newpassword)){
			alert("密码必须至少包含一个数字");
			return false;
		}else if (regex3.test(newpassword.toUpperCase())) {
			alert("同一数字或字母不能出现连续三次重复");
			return false;
        }else if(regex4.test(newpassword.toUpperCase())){
        	alert("不能使用连续4位数字或字母升序或降序排列");
        	return false;
        }else if (!CountChar(newpassword.toUpperCase(), 2, 3)) {
        	alert("2个数字或字母不能出现连续3次重复");
        	return false;
        }else if (!CountChar(newpassword.toUpperCase(), 3, 2)) {
        	alert("3个数字或字母不能出现连续2次重复");
        	return false;
        }else{
        	if ($("input[name=oldpassword]").val() == $("input[name=newpassword]").val()){
				alert("两次输入密码相同");
				return false;
			}
      }
      $("input[name=newpassword]").val(base64encode(utf16to8(newpassword)));
      $("input[name=oldpassword]").val(base64encode(utf16to8(oldpassword)));
      
}
</script>
{include file="public/admin_foot.html"}



